import { useRef, forwardRef } from 'react';

const A2_1 = forwardRef(A2);

function A1() {
  const a1 = useRef(null);
  return (
    <div>
      <button
        onClick={() => {
          a1.current.value = '123';
        }}
      >
        给a2组件赋值
      </button>
      <A2_1 ref={a1} />
    </div>
  );
}

function A2(props, ref) {
  return (
    <div>
      <input ref={ref} type="text" />
    </div>
  );
}

export default A1;
